﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace ZHDJ.Data.Models.Common
{
    /// <summary>
    /// 临时变量
    /// </summary>
    public class TempPara:EntityBase
    {
        public string Key { get; set; }
        public string Value { get; set; }


        public static void UpdateInitBranchRelation(string value)
        {
            Update("InitBranchRelation", value);
        }
        public static string GetInitBranchRelation()
        {
           return Get("InitBranchRelation");
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static void Update(string key,string value)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "Parakey",
                    Value = key
                },
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "Paravalue",
                    Value = value
                }
            };
            string sql = @"update  tbltemppara set ParaValue=?Paravalue WHERE Parakey =?Parakey";
             MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
           
        }
        public static string Get(string key)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "Parakey",
                    Value = key
                }
            };
            string sql = @"SELECT Paravalue FROM tbltemppara WHERE Parakey = ?Parakey";
            Object obj = MySqlHelper.ExecuteScalar(sql, parameters.ToArray());
            if (obj != null) return obj.ToString();
            else return "";
        }

    }



}
